package com.itheima;

import java.util.Random;

public class VerificationCode {

    public static void main(String[] args) {

        String code = getCode(4);
        System.out.println(code);

//        String code2 = createCode(5);
//        System.out.println(code2);
    }
    //随机字符
    private static final char[] CHARS = {
            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
            'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
            'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
            'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
            'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
    };
    private static String createCode(int i) {
        StringBuilder sb = new StringBuilder();
        for (int j = 0; j < i; j++) {
            int index = (int) (Math.random() * CHARS.length);
            sb.append(CHARS[index]);
        }
        return sb.toString();
    }

    public static String getCode( int n) {
        Random random = new Random();
        String code = "";
        for (int j = 0; j < n; j++) {
//            int type = random.nextInt(3);
            int type = 1;
            switch (type) {
                case 0: //数字
                    int number = random.nextInt(10);
                    code += number;
                    System.out.println(number);
                    break;
                case 1: //大写字母
                    int flowchartNumber = random.nextInt(65,91);
                    char c = (char) flowchartNumber;
                    System.out.println(c);
                    code += c;
                    break;
                case 2: //小写字母
                    int highcharNumber = random.nextInt(97,123);
                    char d = (char) highcharNumber;
                    System.out.println(d);
                    code += d;
                    break;
            }
        }
        return code;
    }


}
